package com.xzh.wms.listener;

import com.xzh.wms.dto.InventoryOptionDTO;
import com.xzh.wms.event.InventoryOptionEvent;
import com.xzh.wms.service.InventoryService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;

public class InventoryListener implements ApplicationListener<InventoryOptionEvent> , ApplicationContextAware {


    private ApplicationContext applicationContext;

    @Override
    public void onApplicationEvent(InventoryOptionEvent event) {
        InventoryOptionDTO dto = (InventoryOptionDTO)(event.getSource());
        InventoryService bean = applicationContext.getBean(InventoryService.class);
        bean.process(dto);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
